package annotation;

import java.io.File;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;

public class JAXBexample {

	public static void main(String[] args) {
		Student student = new Student("Kevin", "male", 20);
		student.setId(321);
		
		JAXBContext context;
		try {
			context = JAXBContext.newInstance(Student.class);
			Marshaller m = context.createMarshaller();
			m.marshal(student, new File("student.xml"));
			
			
			Unmarshaller um = context.createUnmarshaller();
			Object obj = um.unmarshal(new File("student.xml"));
			
			if(obj instanceof Student) {
				Student student2 = (Student) obj;
				System.out.println("Student2: " + student2);
			}
		} catch (JAXBException e) {
			e.printStackTrace();
		}
	}

}
